<?php
/**
 * Created by PhpStorm.
 * User: gzc0918
 * Date: 2021-08-08
 * Time: 13:19
 */

namespace IMooc;


use IMooc\Database\MySQLi;

class User
{
    protected $tableName = 'user';
    public $id;
    public $name;
    public $mobile;
    public $regtime;
    protected $db;
    function __construct($id)
    {
        $this->db = new MySQLi();
        $this->db->connect('127.0.0.1', 'root', 'root', 'test');
        $res = $this->db->query("select * from {$this->tableName} where id={$id} limit 1");
        $data = $res->fetch_assoc();
        $this->id = $data['id'];
        $this->name = $data['name'];
        $this->mobile = $data['mobile'];
        $this->regtime = $data['regtime'];
    }
    function __destruct()
    {
        $this->db->query( "UPDATE {$this->tableName} SET name='{$this->name}', mobile='{$this->mobile}',regtime='{$this->regtime}' WHERE id=$this->id");
    }
}